from bs4 import BeautifulSoup
import os, csv

for year in range(1984, 2018):
	wr = open("D:\\KIPRIS\\Citation\\Citation{}.xml".format(year), "w", encoding = "utf-8")
	folder = "D:\\KIPRIS\\Citation\\{}".format(year)
	files = os.listdir(folder)
	for file in files:
		appnum = file[:-4]
		file_dir =  "D:\\KIPRIS\\Citation\\{}\\".format(year) + file
		xml_file = open(file_dir, "r", encoding = "utf-8")
		xml = xml_file.read() + "\n"
		soup = BeautifulSoup(xml, "xml")
		apn = soup.find("ApplicationNumber")
		if apn != None:
			print(apn.text)
			wr.write(xml)